package com.lyn.anr

import com.android.build.api.instrumentation.AsmClassVisitorFactory
import com.android.build.api.instrumentation.ClassContext
import com.android.build.api.instrumentation.ClassData
import com.android.build.api.instrumentation.InstrumentationParameters
import org.objectweb.asm.ClassVisitor

/**
 *
 * @author longyn 2025/07/14
 * @version 1.0.0
 */
abstract class AnrClassVisitorFactory :
    AsmClassVisitorFactory<InstrumentationParameters.None> {


    override fun isInstrumentable(classData: ClassData): Boolean {
        val className = classData.className
        if (className.startsWith("com.lyn.anr")){
            return false
        }
        if (className.startsWith("androidx.")){
            return false
        }
        if (className.startsWith("android.")){
            return false
        }
        if (className.startsWith("java.")){
            return false
        }
        if (className.startsWith("org.")){
            return false
        }
        if (className.startsWith("kotlin.")){
            return false
        }
        return true
    }

    override fun createClassVisitor(
        classContext: ClassContext,
        nextClassVisitor: ClassVisitor
    ): ClassVisitor {
        return AnrClassVisitor(nextClassVisitor)
    }
}